﻿using AppEszköz.Log.Writers;
using System;
namespace AppEszköz.Log
{
    public sealed class Logger
    {
        private Logger()
        {
        }

        public static void Write(string message)
        {
            Logger.Write(1, message, "General", 1, (string)null);
        }

        public static void Write(int eventId, string message, string category, int priority, string extendedInfo)
        {
            Logger.Write(new LogEntry()
            {
                EventId = eventId,
                Message = message,
                Category = category,
                Priority = priority,
                ExtendedInfo = extendedInfo
            });
        }

        public static void Write(LogEntry log)
        {
            if (log == null)
                throw new ArgumentNullException("log");
            if (log.Priority < LoggerSettings.Level)
                return;
            Type type = Type.GetType("AppTools.Log.Writers." + LoggerSettings.Writer, false, true);
            if (type == null)
                throw new MissingMemberException("Invalid LogWriter specified in configuration");
            LogWriter logWriter = (LogWriter)Activator.CreateInstance(type);
            logWriter?.Write(log);
        }
    }
}
